//
//  StoreListViewController.m
//  LiTianDecoration
//
//  Created by zero on 2018/7/13.
//  Copyright © 2018年 administrator. All rights reserved.
//

#import "StoreListViewController.h"
#import "StoreListDiscountCell.h"
#import "StorefrontDetailViewController.h"
#import "HSQPublicAdressView.h"

#import "StoreListCell.h"
#import "StoreListModel.h"
#import "DatasModel.h"
@interface StoreListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tabV;
@property (nonatomic,strong)NSMutableArray *array_dataSource;
///页数
@property (nonatomic,assign) NSInteger page;
///购买提示
@property (weak, nonatomic) IBOutlet UIView *view_show;
///选择地址
@property (weak, nonatomic) IBOutlet UIButton *button_address;

@end

@implementation StoreListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self request:NO];

}
- (void)request:(BOOL)isbool{
    
    __weak typeof(self)weakSelf = self;
    [[HTTPRequest shareApiHelper]GETExhibition:self.view UrlString:@"http://java.bizpower.com/api/chain/list?areaId2=40&areaId3=55&goodsId=765" Parameters:[StoreListModel chainAreaId2:1 areaId3:2 goodsId:self.good_id] Success:^(id resultObject) {
        [weakSelf.array_dataSource addObjectsFromArray:[[DatasModel yy_modelWithJSON:resultObject]chainList]];
        [weakSelf.tabV reloadData];

    } Error:^{
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.array_dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    StoreListModel *model = self.array_dataSource[indexPath.row];
    return 90+model.chainPromotionList.count*25;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    StoreListModel *model = self.array_dataSource[indexPath.row];
    
    if (indexPath.row == 0) {
        StoreListDiscountCell *cell = (StoreListDiscountCell *)[tableView dequeueReusableCellWithIdentifier:@"StoreListDiscountCell"];
        cell.model = model;
        return cell;
    } else {
        StoreListCell *cell = (StoreListCell *)[tableView dequeueReusableCellWithIdentifier:@"StoreListCell"];
        cell.model = model;
        return cell;
    }
}
- (NSMutableArray *)array_dataSource{
    if (!_array_dataSource) {
        _array_dataSource = [NSMutableArray new];
    }
    return _array_dataSource;
}

/**
 打开提示

 @param sender <#sender description#>
 */
- (IBAction)buttonShowAction:(id)sender {
    _view_show.hidden = NO;
}
/**
 关闭提示

 @param sender <#sender description#>
 */
- (IBAction)buttonCancleAction:(id)sender {
    _view_show.hidden = YES;
}
/**
 选择地址

 @param sender <#sender description#>
 */
- (IBAction)buttonAddressAction:(id)sender {
    
    
    HSQPublicAdressView *adressView = [HSQPublicAdressView initAdressView];
    
    adressView.placherString = @"配送至";
    
    [adressView ShowAdressView];
    
    __weak typeof(self)weakSelf = self;
    adressView.chooseFinish = ^(NSString *adress,NSString *ProvinceId, NSString *cityId, NSString *AreaId){
        
        HSQLog(@"===%@==%@===%@==%@",adress,ProvinceId,cityId,AreaId);
        [weakSelf.button_address setTitle:adress forState:UIControlStateNormal];
    };
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSIndexPath *indexPath = [_tabV indexPathForSelectedRow];
    StorefrontDetailViewController *vc = (StorefrontDetailViewController *)segue.destinationViewController;
    vc.model = self.array_dataSource[indexPath.row];
    
}


@end
